﻿using MediatR;
using SlaughterItem.Common.Domains.Manages;
using SlaughterItem.Common.Dtos;
using SlaughterItem.Common.Infrastructures.Interfaces;
using SlaughterItem.Enum;

namespace SlaughterItem.API.Application.Commands.Week01.SectionCommands
{
    public class SectionShowHandler1 : IRequestHandler<SectionShowCommand1, Result>
    {
        public IBaseRepositoryGet<Sections> sections;
        public IBaseRepositoryGet<Business> business;

        public SectionShowHandler1(IBaseRepositoryGet<Sections> sections, IBaseRepositoryGet<Business> business)
        {
            this.sections = sections;
            this.business = business;
        }

        public async Task<Result> Handle(SectionShowCommand1 request, CancellationToken cancellationToken)
        {
            //定义返回值
            var result = new Result() { Code = (int)CommonErrorCode.Search };
            var data = (from b in business.GetAll()
                        select new
                        {
                            BusinessId = b.BusinessId,
                            BusinessName = b.BusinessName,
                        }).ToList();

            if (data != null)
            {
                result.Data = data;
                result.Code = (int)CommonErrorCode.Success;
                return result;
            }
            else
            {
                return result;
            }
        }
    }
}
